package com.jiaquyun.jcps.mode.manager

import com.jiaquyun.jcps.app.BaseApplication
import com.jiaquyun.jcps.entity.*
import com.jiaquyun.jcps.mode.api.OrderApi
import com.lemlin.network.HttpServiceData
import com.lemlin.network.HttpServiceManager
import com.lemlin.network.HttpServiceSubscribe
import com.lemlin.network.SubscribeListener
import io.reactivex.disposables.Disposable

class OrderManager : HttpServiceManager<OrderApi>(OrderApi::class.java) {


    /**
     * 订单列表
     */
    fun orderList(
        lat: String, lng: String, type: String, listener: SubscribeListener<OrderListResponse>
    ): Disposable =
        subscribe(
            apiService.orderList(BaseApplication.userToken(), lat, lng, type),
            HttpServiceSubscribe(listener)
        )

    /**
     * 接单
     */
    fun orderReceiving(
        riderOrderId: String, listener: SubscribeListener<HttpServiceData>
    ): Disposable =
        subscribe(
            apiService.orderReceiving(BaseApplication.userToken(), riderOrderId),
            HttpServiceSubscribe(listener)
        )

    /**
     * 確認取單
     */
    fun orderWithdrawal(
        riderOrderId: String,orderSn:String, listener: SubscribeListener<HttpServiceData>
    ): Disposable =
        subscribe(
            apiService.orderWithdrawal(BaseApplication.userToken(), riderOrderId,orderSn),
            HttpServiceSubscribe(listener)
        )

    /**
     * 确认送达
     * */
    fun orderService(
        riderOrderId: String, images: String, listener: SubscribeListener<HttpServiceData>
    ): Disposable =
        subscribe(
            apiService.orderService(BaseApplication.userToken(), riderOrderId, images),
            HttpServiceSubscribe(listener)
        )

    /**
     *获取订单列表tab
     * */
    fun orderListTab(
        listener: SubscribeListener<OrderTabResponse>
    ): Disposable =
        subscribe(
            apiService.orderListTab(BaseApplication.userToken()),
            HttpServiceSubscribe(listener)
        )

    /**
     * 订单详情
     * */
    fun orderDetails(
        lat: String, lng: String, riderOrderId: String,
        listener: SubscribeListener<OrderDetailsResponse>
    ): Disposable =
        subscribe(
            apiService.orderDetails(BaseApplication.userToken(), lat, lng, riderOrderId),
            HttpServiceSubscribe(listener)
        )

    /**
     * 完成订单详情
     * */
    fun orderDetailsToday(
        riderOrderId: String, listener: SubscribeListener<OrderTodayDetailsResponse>
    ): Disposable =
        subscribe(
            apiService.orderDetailsToday(BaseApplication.userToken(), riderOrderId),
            HttpServiceSubscribe(listener)
        )

    /**
     * 接单记录
     * */
    fun orderLog(
        page: String, limit: String, listener: SubscribeListener<OrderTodayListResponse>
    ): Disposable =
        subscribe(
            apiService.orderLog(BaseApplication.userToken(), page, limit),
            HttpServiceSubscribe(listener)
        )
}